#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

#define DEV_NMAE "/dev/hello_char"

int main(void)
{
    int fd;
    int len;
    char send[128] = "test hello char";
    char recv[128] = {0};

    printf("[%s][%d]\r\n", __func__, __LINE__);

    fd = open(DEV_NMAE, O_RDWR);
    if (fd < 0)
    {
        printf("[%s][%d] open %s error, erron:%d:%s\r\n", __func__, __LINE__, DEV_NMAE, errno, strerror(errno));
        return -1;
    }

    len = write(fd, send, strlen(send));
    printf("[%s][%d] write return len:%d\r\n", __func__, __LINE__, len);

    memset(recv, 0, sizeof(recv));
    len = read(fd, recv, sizeof(recv));
    printf("[%s][%d] read %d return len:%d, %s\r\n", __func__, __LINE__, sizeof(recv), len, recv);

    memset(recv, 0, sizeof(recv));
    len = read(fd, recv, 10);
    printf("[%s][%d] read 10 return len:%d, %s\r\n", __func__, __LINE__, len, recv);

    close(fd);

    return 0;
}
